package com.cyy.dyeing.controller;

import com.cyy.dyeing.common.Result;
import com.cyy.dyeing.dto.MenuDto;
import com.cyy.dyeing.service.ModuleService;
import com.cyy.dyeing.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: cyy
 * @Date: 2024/7/24
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @Autowired
    private ModuleService moduleService;

    /**
     * 变更角色权限
     *
     * @param ro_id
     * @param moduleIds
     * @return
     */
    @PutMapping("/module/{ro_id}")
    public Result confirmRoleModules(@PathVariable Integer ro_id,
                                     @RequestBody Integer[] moduleIds) {

        roleService.confirmRoleModules(ro_id, moduleIds);
        return Result.ok();
    }

    /**
     * 获取角色权限 【菜单】列表
     * @param ro_id
     * @return
     */
    @GetMapping("/{ro_id}")
    public Result getRoleModuleList(@PathVariable Integer ro_id){
        //调用业务层查询
        List<MenuDto> list = moduleService.getRoleMenuList(ro_id);
        return Result.ok(list);
    }
}
